package com.movies.utils;

import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by admin on 2017/3/26.
 */
public class MD5Utils {

    private static MessageDigest MD5;

    private static BASE64Encoder base64en = new BASE64Encoder();

    static {

        try {
            MD5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            //MD5 = null;
        }
    }

    public static String encode(String plainText) throws UnsupportedEncodingException {
        byte[] plainTextByte = MD5.digest(plainText.getBytes("UTF-8"));
        return base64en.encode(plainTextByte);
    }
}
